package com.ych.util;

import org.apache.kafka.clients.producer.Partitioner;
import org.apache.kafka.common.Cluster;
import org.apache.kafka.common.PartitionInfo;

import java.util.List;
import java.util.Map;
import java.util.Random;

public class KafkaPartition implements Partitioner {
    Random r=new Random();
    @Override
    public int partition(String topic, Object key, byte[] key_arr, Object data, byte[] data_arr, Cluster cluster) {
        List<PartitionInfo> partitions = cluster.partitionsForTopic(topic);
        int numPartitions = partitions.size();
        return r.nextInt(numPartitions);//随机
    }
    public void close() {}
    //map中是配置信息
    public void configure(Map<String, ?> map) {}
}
